package com.aiobc.file.dto;

import com.aiobc.file.enums.RespCodeEnum;
import lombok.Data;

/**
 * @author fengzh
 * @className BaseResponse
 * @date 2020/4/16 11:20
 */
@Data
public class BaseResponse<T> {

    private boolean success;

    private String code;

    private String message;

    private T data;

    public BaseResponse() {
    }

    public BaseResponse(boolean success, RespCodeEnum respCodeEnum) {
        this(success, respCodeEnum.getCode(), respCodeEnum.getMessage());
    }

    public BaseResponse(boolean success, RespCodeEnum respCodeEnum, T data) {
        this(success, respCodeEnum.getCode(), respCodeEnum.getMessage(), data);
    }

    public BaseResponse(boolean success, String code, String message) {
        this(success, code, message, null);
    }

    public BaseResponse(boolean success, String code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static BaseResponse createSuccess() {
        return new BaseResponse(true, RespCodeEnum.SUCCESS);
    }

    public static <T> BaseResponse<T> createSuccess(T data) {
        return new BaseResponse(true, RespCodeEnum.SUCCESS, data);
    }

    public static BaseResponse createFail(RespCodeEnum respCodeEnum) {
        return new BaseResponse(false, respCodeEnum);
    }

    public static BaseResponse createFail(String message) {
        return new BaseResponse(false, RespCodeEnum.FAIL.getCode(), message);
    }

    public static BaseResponse createFail(String code, String message) {
        return new BaseResponse(false, code, message);
    }

}
